package android.content;

import java.util.*;

/**
 * @author slc
 * @date 2022/03/29 上午 11:35
 */
public abstract class BroadcastReceiver{
    private final Set<String> monitorActionSet = new HashSet<>();

    public List<String> getMonitorActionSet() {
        return Arrays.asList(monitorActionSet.toArray(new String[0]));
    }

    public void addMonitorActions(Collection<String> monitorActionSet) {
        this.monitorActionSet.addAll(monitorActionSet);
    }

    public void addMonitorAction(String action) {
        this.monitorActionSet.add(action);
    }

    public boolean isMonitor(String... actions) {
        if (actions != null && actions.length > 0) {
            for (String action : actions) {
                if (monitorActionSet.contains(action)) {
                    return true;
                }
            }
        }
        return false;
    }

    public void notifyReceive(Context context, Intent intent) {
        if (isMonitor(intent.getAction())) {
            onReceive(context, intent);
        }
    }

    public abstract void onReceive(Context context, Intent intent);
}
